package com.cloudfun.campusshare.controller;

import com.alibaba.fastjson.JSON;
import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.constant.RoleType;
import com.cloudfun.campusshare.common.model.vo.BillListVO;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.response.PageResult;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.common.security.AuthenticationHolder;
import com.cloudfun.campusshare.service.BillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/4/17 9:59
 * @description :
 */
@Slf4j
@RestController
@Api(value = "账单模块")
@RequestMapping("/v1//bill")
public class BillController {

    @Autowired
    private BillService billService;

    @ApiOperation(value = "账单查询")
    @GetMapping("/search")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult<PageResult<BillListVO>> search(Pageable pageable) {
        PageResult<BillListVO> pageResult = billService.search(pageable);
        log.info("用户id ->{},查询消费记录结果 ->{}", AuthenticationHolder.getUserId(), JSON.toJSONString(pageResult));
        return BaseResultFactory.produceResult(Code.SUCCESS, pageResult);
    }
}
